package it.polimi.traveldream.entity;

import it.polimi.traveldream.dto.ScheduleDTO;

import java.io.Serializable;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

/**
 * The persistent class for the schedule database table.
 * 
 */
@Entity
@Table(name = "schedule")
@NamedQuery(name = "Schedule.findAll", query = "SELECT s FROM Schedule s")
public class Schedule implements Serializable {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private SchedulePK id;

	@NotNull
	private Integer day;

	@ManyToOne
	@JoinColumn(name = "activity", nullable = false)
	private Activity activity;

	@ManyToOne
	@JoinColumn(name = "package", nullable = false)
	private Package pack;

	public Schedule() {
	}

	public Schedule(ScheduleDTO sched) {
		this.setActivity(new Activity(sched.getActivity()));
		this.setDay(sched.getDay());
		this.setId(new SchedulePK());
	}

	public SchedulePK getId() {
		return this.id;
	}

	public void setId(SchedulePK id) {
		this.id = id;
	}

	public Integer getDay() {
		return this.day;
	}

	public void setDay(Integer day) {
		this.day = day;
	}

	public Activity getActivity() {
		return this.activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	public Package getPack() {
		return this.pack;
	}

	public void setPack(Package pack) {
		this.pack = pack;
	}

	public ScheduleDTO convertToDTO() {
		ScheduleDTO scheduleDTO = new ScheduleDTO();
		scheduleDTO.setActivity(this.getActivity().convertToDTO());
		scheduleDTO.setDay(this.getDay());
		return scheduleDTO;
	}

}